-
Notifications
You must be signed in to change notification settings - Fork 3
/
tests_exit_labyrinth.py
84 lines (73 loc) · 1.94 KB
/
tests_exit_labyrinth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import unittest
import sys
from io import StringIO
from nearest_exit_labyrinth import main as exit_labyrinth
class LabyrinthTest(unittest.TestCase):
def test_labyrinth_9x7(self):
user_input = """9
7
*********
*----**--
**-*----*
*--*-*-**
*s*--*-**
**------*
*******-*"""
expected_output = "Shortest exit: URUURRDRRRUR\n"
output = StringIO()
try:
sys.stdin = StringIO(user_input)
sys.stdout = output
exit_labyrinth()
self.assertEqual(output.getvalue(), expected_output)
finally:
sys.stdin = sys.__stdin__
sys.stdout = sys.__stdout__
def test_labyrinth_4x3(self):
user_input = """4
3
****
*-s*
****"""
expected_output = "No exit!\n"
output = StringIO()
try:
sys.stdin = StringIO(user_input)
sys.stdout = output
exit_labyrinth()
self.assertEqual(output.getvalue(), expected_output)
finally:
sys.stdin = sys.__stdin__
sys.stdout = sys.__stdout__
def test_labyrinth_4x2(self):
user_input = """4
2
****
***s"""
expected_output = "Start is at the exit.\n"
output = StringIO()
try:
sys.stdin = StringIO(user_input)
sys.stdout = output
exit_labyrinth()
self.assertEqual(output.getvalue(), expected_output)
finally:
sys.stdin = sys.__stdin__
sys.stdout = sys.__stdout__
def test_labyrinth_2x2(self):
user_input = """2
2
**
**"""
expected_output = "No exit!\n"
output = StringIO()
try:
sys.stdin = StringIO(user_input)
sys.stdout = output
exit_labyrinth()
self.assertEqual(output.getvalue(), expected_output)
finally:
sys.stdin = sys.__stdin__
sys.stdout = sys.__stdout__
if __name__ == '__main__':
unittest.main()